package com.hjm.project.merchantInfo.merchantInfo.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hjm.common.api.cq.PublicJgRequest;
import com.hjm.common.exception.BusinessException;
import com.hjm.common.push.AgentAsyncService;
import com.hjm.common.utils.DateUtils;
import com.hjm.common.utils.HttpUtils;
import com.hjm.common.utils.StringUtils;
import com.hjm.common.utils.Utils;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.common.utils.request.AutoLoadData;
import com.hjm.common.utils.security.ShiroUtils;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.framework.config.CustomConfig;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.framework.web.page.TableDataInfo;
import com.hjm.project.accounts.accounts.domain.Accounts;
import com.hjm.project.accounts.accounts.service.IAccountsService;
import com.hjm.project.agentInfo.agentActActive.domain.AgentActActive;
import com.hjm.project.agentInfo.agentActActive.utils.AgentPriceCommon;
import com.hjm.project.agentInfo.agentInfo.domain.AgentInfo;
import com.hjm.project.agentInfo.agentInfo.service.IAgentInfoService;
import com.hjm.project.agentInfo.agentPolicy.domain.AgentPolicy;
import com.hjm.project.area.domain.Area;
import com.hjm.project.area.service.IAreaService;
import com.hjm.project.clientImg.clientImg.domain.ClientImg;
import com.hjm.project.clientImg.clientImg.service.IClientImgService;
import com.hjm.project.formalPos.branchPos.domain.BranchPos;
import com.hjm.project.formalPos.branchPos.service.IBranchPosService;
import com.hjm.project.formalPos.formalPos.domain.FormalPos;
import com.hjm.project.formalPos.formalPos.service.IFormalPosService;
import com.hjm.project.merchantInfo.merRecord.domain.MerUpdateAreaRecord;
import com.hjm.project.merchantInfo.merchantInfo.domain.MerchantInfo;
import com.hjm.project.merchantInfo.merchantInfo.domain.MerchantRateShow;
import com.hjm.project.merchantInfo.merchantInfo.domain.MerchantShow;
import com.hjm.project.merchantInfo.merchantInfo.service.IMerchantInfoService;
import com.hjm.project.merchantInfo.merchantInfo.util.MerchantCommon;
import com.hjm.project.merchantInfo.merchantInfo.util.MerchantRateUtils;
import com.hjm.project.merchantInfo.merchantRate.domain.MerchantRate;
import com.hjm.project.merchantInfo.merchantRate.service.IMerchantRateService;
import com.yxhd.encrypt.EncryptUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 商户信息Controller
 *
 * @author LOVE
 * @date 2020-11-23
 */
@Controller
@RequestMapping("/merchantInfo/merchantInfo")
public class MerchantInfoController extends BaseController {
    private String prefix = "merchantInfo/merchantInfo";

    @Resource
    private IMerchantInfoService merchantInfoService;
    @Resource
    private IClientImgService clientImgService;
    @Resource
    private IAreaService areaService;           //区域
    @Resource
    private IAccountsService accountsService;   //账户
    @Resource
    private IFormalPosService posService;       //商户机具
    @Resource
    private IBranchPosService branchPosService; //机具分配
    @Resource
    private IAgentInfoService agentInfoService; //代理商信息
    @Resource
    private IMerchantRateService merchantRateService;
    @Resource
    private AgentAsyncService agentAsyncService;


    @GetMapping()
    public String merchantInfo() {
        return prefix + "/merchantInfo";
    }

    @RequiresPermissions("merchantInfo:merchantInfo:dataMerInfo")
    @GetMapping("/dataMerInfo")
    public String dataMerInfo() {
        return prefix + "/dataMerInfo";
    }

    /**
     * 查询商户信息列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MerchantInfo merchantInfo) throws Exception {
        startPage();
        if (StringUtils.isNotEmpty(merchantInfo.getLinkPhone())) {
            merchantInfo.setLinkPhone(EncryptUtils.getEncrypt(merchantInfo.getLinkPhone()));
        }
        if (StringUtils.isNotEmpty(merchantInfo.getLegalCerno())) {
            merchantInfo.setLegalCerno(EncryptUtils.getEncrypt(merchantInfo.getLegalCerno()));
        }
        if (ShiroUtils.isAgent()) {
            merchantInfo.setLoginAgentNum(ShiroUtils.getLoginAgentNum());
        }
        List<MerchantInfo> list = merchantInfoService.selectMerchantInfoList(merchantInfo);
        for (MerchantInfo mer : list) {
            if (mer.getLegalCerno() != null && mer.getLegalCerno().indexOf("*") == -1 && mer.getLegalCerno().length() > 19) {
                mer.setLegalCerno(EncryptUtils.getDecrypt(mer.getLegalCerno()));
            }
            if (mer.getShowLinkphone() != null && mer.getShowLinkphone().indexOf("*") == -1  && mer.getShowLinkphone().length() == 11) {
                mer.setShowLinkphone(Utils.dealPhone(mer.getShowLinkphone()));
            }
        }
        return getDataTable(list);
    }


    /**
     * 数据管理-商户查询
     */
    @RequiresPermissions("merchantInfo:merchantInfo:merInfoList")
    @PostMapping("/merInfoList")
    @ResponseBody
    public TableDataInfo merInfoList(MerchantInfo merchantInfo) throws Exception {
        startPage();
        if (StringUtils.isNotEmpty(merchantInfo.getLinkPhone())) {
            merchantInfo.setLinkPhone(EncryptUtils.getEncrypt(merchantInfo.getLinkPhone()));
        }
        if (StringUtils.isNotEmpty(merchantInfo.getLegalCerno())) {
            merchantInfo.setLegalCerno(EncryptUtils.getEncrypt(merchantInfo.getLegalCerno()));
        }

        List<MerchantInfo> list = merchantInfoService.selectDataMerInfoList(merchantInfo);
        for (int i = 0; i < list.size(); i++) {
            if (StringUtils.isNotEmpty(list.get(i).getLegalCerno())) {
                list.get(i).setLegalCerno(Utils.dealCard(EncryptUtils.getDecrypt(list.get(i).getLegalCerno())));
            }
            if (StringUtils.isNotEmpty(list.get(i).getLinkPhone())) {
                list.get(i).setLinkPhone(Utils.dealPhone(EncryptUtils.getDecrypt(list.get(i).getLinkPhone())));
            }
        }
        return getDataTable(list);
    }


    /**
     * 导出商户信息列表
     */
    @RequiresPermissions("merchantInfo:merchantInfo:export")
    @Log(title = "商户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MerchantInfo merchantInfo) {
        List<MerchantInfo> list = merchantInfoService.selectMerchantInfoList(merchantInfo);
        ExcelUtil<MerchantInfo> util = new ExcelUtil<MerchantInfo>(MerchantInfo.class);
        return util.exportExcel(list, "merchantInfo");
    }

    /**
     * 新增商户信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存商户信息
     */
    @RequiresPermissions("merchantInfo:merchantInfo:add")
    @Log(title = "商户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MerchantInfo merchantInfo) {
        return toAjax(merchantInfoService.insertMerchantInfo(merchantInfo));
    }

    /**
     * 修改商户信息
     */
    @GetMapping("/edit/{merno}")
    public String edit(@PathVariable("merno") String merno, ModelMap mmap) {
        MerchantInfo merchantInfo = merchantInfoService.selectMerchantInfoById(merno);
        mmap.put("merchantInfo", merchantInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存商户信息
     */
    @RequiresPermissions("merchantInfo:merchantInfo:edit")
    @Log(title = "商户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MerchantInfo merchantInfo) {
        return toAjax(merchantInfoService.updateMerchantInfo(merchantInfo));
    }

    /**
     * 删除商户信息
     */
    @RequiresPermissions("merchantInfo:merchantInfo:remove")
    @Log(title = "商户信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(merchantInfoService.deleteMerchantInfoByIds(ids));
    }

    @RequiresPermissions("merchantInfo:merchantInfo:view")
    @GetMapping("/userRecord/{merNo}")
    public String userRecord(@PathVariable("merNo") String merNo, ModelMap mmap) {
        mmap.put("merNo", merNo);
        return "merchantInfo/records/records";
    }

    @RequiresPermissions("merchantInfo:merchantInfo:lookImg")
    @GetMapping("/lookImg/{merNo}")
    public String lookImg(@PathVariable("merNo") String merNo, ModelMap mmap) {
        ClientImg clientImg = new ClientImg();
        clientImg.setClientno(merNo);
        clientImg.setObjType(0L);
        List<ClientImg> clientImgs = clientImgService.selectclientImgList(clientImg);
        mmap.put("merNo", merNo);
        mmap.put("clientImgs", clientImgs);
        mmap.put("imgUrl", CustomConfig.getImgUrl());
        return prefix + "/lookImg";
    }

    /**
     * 商户注销页面跳转
     */
    @GetMapping("/cancelMer/{merNo}")
    public String cancelMer(@PathVariable("merNo") String merNo, ModelMap mmap) {
        MerchantInfo merchantInfo = merchantInfoService.selectMerchantInfoById(merNo);
        mmap.put("merchantInfo", merchantInfo);
        return prefix + "/cancelMer";
    }

    /**
     * 保存商户商注销
     */
    @PostMapping("/saveCancel")
    @RequiresPermissions("agentInfo:agentInfo:cancelAgent")
    @Log(title = "商户注销", businessType = BusinessType.UPDATE)
    @ResponseBody
    public AjaxResult saveCancel(MerchantInfo merchantInfo) {
        return merchantInfoService.saveCancel(merchantInfo);
    }

    /**
     * 商户修改注册地址
     */
    @GetMapping("/updateAddress/{merNo}")
    public String updateAddress(@PathVariable("merNo") String merNo, ModelMap mmap) {
        MerchantInfo merchantInfo = merchantInfoService.selectMerchantInfoById(merNo);

        String addressCode = merchantInfo.getMerCode();
        String province = "", city = "";
        if (StringUtils.isNotEmpty(addressCode)) {
            String[] addressArray = addressCode.split(",");
            if (addressArray.length > 1) {
                if (StringUtils.isNotEmpty(addressArray[0])) {
                    province = addressArray[0];
                    mmap.put("province", addressArray[0]);
                }
                if (StringUtils.isNotEmpty(addressArray[1])) {
                    city = addressArray[1];
                    mmap.put("city", addressArray[1]);
                }
            }
            if (addressArray.length > 2) {
                if (StringUtils.isNotEmpty(addressArray[2])) {
                    mmap.put("area", addressArray[2]);
                }
            }
        }
        List<Area> pList = new ArrayList<>();
        List<Area> cList = new ArrayList<>();
        List<Area> aList = new ArrayList<>();
        List<Area> areas = areaService.selectAreaList(null);
        for (Area area : areas) {
            if (area.getAreaType() == 0) {
                pList.add(area);
            } else if (area.getAreaType() == 1 && province.equals(area.getParentId())) {
                cList.add(area);
            } else if (area.getAreaType() == 2 && city.equals(area.getParentId())) {
                aList.add(area);
            }
        }
        mmap.put("pList", pList);
        mmap.put("cList", cList);
        mmap.put("aList", aList);
        mmap.put("merchantInfo", merchantInfo);
        return prefix + "/updateAddress";
    }

    /**
     * 保存修改注册地址
     */
    @PostMapping("/updateAddress")
    @RequiresPermissions("agentInfo:agentInfo:updateAddress")
    @Log(title = "商户修改注册地址", businessType = BusinessType.UPDATE)
    @ResponseBody
    public AjaxResult updateAddress(MerchantInfo merchantInfo, @RequestParam Map<String, String> params) throws Exception {
        params.put("addMan",this.getSysUser().getLoginName());
        return merchantInfoService.updateAddress(merchantInfo, params);
    }

    /**
     * 商户修改结算银行页面跳转
     */
    @GetMapping("/updateBank/{merNo}")
    public String updateBank(@PathVariable("merNo") String merNo, ModelMap mmap) throws Exception {
        //商户信息
        MerchantInfo merchantInfo = merchantInfoService.selectMerchantInfoById(merNo);
        mmap.put("merchantInfo", merchantInfo);
        //商户账户信息
        Accounts account = new Accounts();
        account.setSeqId(merchantInfo.getMerno());
        Accounts accounts = accountsService.selectAccounts(account);
        //根据地区名称获取代号
        String addressName = accounts.getAreaName();
        String province = "";
        String city = "";
        String areaName = "";
        if (StringUtils.isNotEmpty(addressName)) {
            String[] addressArray = addressName.split(",");
            if (addressArray.length > 1) {
                if (StringUtils.isNotEmpty(addressArray[0])) {
                    province = addressArray[0];
                    Map<String, Object> params = new HashMap();
                    params.put("area_name", province);
                    params.put("area_type", "0");
                    Map<String, Object> areaCodeMap = areaService.findQBAreaCode(params);
                    province = String.valueOf(areaCodeMap.get("AREA_CODE"));
                    mmap.put("province", String.valueOf(areaCodeMap.get("AREA_CODE")));
                }
                if (StringUtils.isNotEmpty(addressArray[1])) {
                    city = addressArray[1];
                    Map<String, Object> params = new HashMap();
                    params.put("area_name", city);
                    params.put("area_type", "1");
                    Map<String, Object> areaCodeMap = areaService.findQBAreaCode(params);
                    city = String.valueOf(areaCodeMap.get("AREA_CODE"));
                    mmap.put("city", String.valueOf(areaCodeMap.get("AREA_CODE")));
                }
            }
            if (addressArray.length > 2) {
                if (StringUtils.isNotEmpty(addressArray[2])) {
                    areaName = addressArray[2];
                    Map<String, Object> params = new HashMap();
                    params.put("area_name", areaName);
                    params.put("area_type", "2");
                    Map<String, Object> areaCodeMap = areaService.findQBAreaCode(params);
                    mmap.put("area", String.valueOf(areaCodeMap.get("AREA_CODE")));
                }
            }
        }
        List<Area> pList = new ArrayList<>();
        List<Area> cList = new ArrayList<>();
        List<Area> aList = new ArrayList<>();
        List<Area> areas = areaService.selectAreaList(null);
        for (Area area : areas) {
            if (area.getAreaType() == 0) {
                pList.add(area);
            } else if (area.getAreaType() == 1 && province.equals(area.getParentId())) {
                cList.add(area);
            } else if (area.getAreaType() == 2 && city.equals(area.getParentId())) {
                aList.add(area);
            }
        }
        mmap.put("pList", pList);
        mmap.put("cList", cList);
        mmap.put("aList", aList);

        accounts.setScreenNum(EncryptUtils.getDecrypt(accounts.getScreenNum()));
        accounts.setScreenIdnum(EncryptUtils.getDecrypt(accounts.getScreenIdnum()));
        accounts.setResphone(EncryptUtils.getDecrypt(accounts.getResphone()));

        mmap.put("accounts", accounts);


        return prefix + "/updateBank";
    }

    /**
     * 总行查找带回
     *
     * @return
     */
    @GetMapping("/selectHeadBank")
    public String selectHeadBank() {
        return prefix + "/selectHeadBank";
    }

    /**
     * 支行查找带回
     */
    @GetMapping("/selectBranchBank/{headBank}")
    public String selectBranchBank(@PathVariable("headBank") String headBank, ModelMap mmap) {
        mmap.put("headBank", headBank);
        return prefix + "/selectBranchBank";
    }

    /**
     * 商户修改结算银行
     */
    @PostMapping("/updateBank")
    @RequiresPermissions("agentInfo:agentInfo:updateBank")
    @Log(title = "商户修改结算银行", businessType = BusinessType.UPDATE)
    @ResponseBody
    public AjaxResult updateBank(@RequestParam Map<String, String> params) {
        return merchantInfoService.updateBank(params);
    }

    /**
     * 商户修改结算银行页面跳转
     */
    @GetMapping("/updateSettle/{merNo}")
    public String updateSettle(@PathVariable("merNo") String merNo, ModelMap mmap) {
        MerchantInfo merchantInfo = merchantInfoService.selectMerchantInfoById(merNo);
        mmap.put("merchantInfo", merchantInfo);
        return prefix + "/updateSettle";
    }

    /**
     * 商户修改冻结状态跳转
     */
    @GetMapping("/updateFreeze/{merNo}")
    public String updateFreeze(@PathVariable("merNo") String merNo, ModelMap mmap) {
        MerchantInfo merchantInfo = merchantInfoService.selectMerchantInfoById(merNo);
        mmap.put("merchantInfo", merchantInfo);
        return prefix + "/updateFreeze";
    }

    /**
     * 保存商户冻结状态
     */
    @PostMapping("/updateFreeze")
    @RequiresPermissions("agentInfo:agentInfo:updateFreeze")
    @Log(title = "商户修改冻结状态", businessType = BusinessType.UPDATE)
    @ResponseBody
    public AjaxResult updateFreeze(MerchantInfo merchantInfo) {
        int i = merchantInfoService.updateMerchantInfo(merchantInfo);
        return toAjax(i);
    }


    /**
     * 保存修改结算类型
     */
    @PostMapping("/updateSettle")
    @RequiresPermissions("agentInfo:agentInfo:updateSettle")
    @Log(title = "商户修改结算类型", businessType = BusinessType.UPDATE)
    @ResponseBody
    public AjaxResult updateSettle(MerchantInfo merchantInfo) {

        return merchantInfoService.updateSettle(merchantInfo);
    }

    /**
     * 查看商户信息
     */
    @GetMapping("/enterpriseInfo")
    public String enterpriseInfo(@RequestParam String merNo, ModelMap mmap) throws Exception {
        //商户信息
        Map merchantInfo = merchantInfoService.findMerchantInfoByMerNo(merNo);
        mmap.put("merchant", merchantInfo);
        return prefix + "/enterpriseInfo";
    }

    /**
     * 查看商户手机号
     */
    @GetMapping("/findPhone")
    public String findPhone(@RequestParam String merNo, ModelMap mmap) throws Exception {
        //商户信息
        Map merchantInfo = merchantInfoService.findMerchantInfoByMerNo(merNo);
        mmap.put("merchant", merchantInfo);
        return prefix + "/findPhone";
    }

    /**
     * 前往商户迁移页面
     */
    @GetMapping("/merMigrate")
    public String merMigrate(@RequestParam String merNo, ModelMap mmap) throws Exception {
        //商户信息
        Map merchantInfo = merchantInfoService.findMerchantInfoByMerNo(merNo);
        mmap.put("merchantInfo", merchantInfo);
        return prefix + "/merMigrate";
    }

    /**
     * 前往商户换机页面
     */
    @GetMapping("/bangding")
    public String bangding(@RequestParam String merNo, ModelMap mmap) throws Exception {
        //商户信息
        Map merchantInfo = merchantInfoService.findMerchantInfoByMerNo(merNo);
        mmap.put("merchantInfo", merchantInfo);
        return prefix + "/bangding";
    }
    /**
     * 前往终端绑定推送页面
     */
    @GetMapping("/posPush")
    public String posPush(@RequestParam String merNo, ModelMap mmap) throws Exception {
        //商户信息
        Map merchantInfo = merchantInfoService.findMerchantInfoByMerNo(merNo);
        mmap.put("merchantInfo", merchantInfo);
        return prefix + "/posPush";
    }
    @GetMapping("/expiry")
    public String expiry(@RequestParam String merNo, ModelMap mmap) throws Exception {
        //商户信息
        Map merchantInfo = merchantInfoService.findMerchantInfoByMerNo(merNo);
        mmap.put("merchantInfo", merchantInfo);
        return prefix + "/expiry";
    }
    /**
     * 商户详情
     */
    @GetMapping("/getMerDetails")
    public String getMerDetails(@RequestParam String merNo, ModelMap mmap){
        Map<String, String> result = null;
        try {
            MerchantInfo merchantInfo = merchantInfoService.selectMerchantInfoById(merNo);
            JSONObject reqData = new JSONObject();
            //reqData.put("applyId",merchantInfo.getOrgSerial());
            reqData.put("mchtNumber",merchantInfo.getLdMerno());
            //reqData.put("orgMerNo",merchantInfo.getOrgMerno());
            //商户信息
            result = PublicJgRequest.getReqData(reqData.toJSONString(), AutoLoadData.queryMerchant,true);
        } catch (Exception e) {
            mmap.put("merchantInfo", "未获取到请求连接,请求渠道异常");
        }
        mmap.put("merchantInfo", StringUtils.isBlank(result.get("respData")) ? JSONObject.toJSONString(result) : result.get("respData"));
        return prefix + "/getMerDetails";
    }

    @PostMapping("/saveBangding")
    @ResponseBody
    @Log(title = "终端绑定", businessType = BusinessType.UPDATE)
    @Transactional
    public AjaxResult saveBangding(@RequestParam Map param) throws Exception {
        String merNo = String.valueOf(param.get("merNo"));
        String sn = String.valueOf(param.get("sn"));
        BranchPos bp = branchPosService.selectBranchPosBySn(sn);
        if (bp == null) {
            return AjaxResult.error("sn不存在或未分配");
        }
        if (bp.getIsbound().intValue() != 0) {
            return AjaxResult.error("当前机器已绑定");
        }
        FormalPos fp = new FormalPos();
        fp.setPosno(bp.getPosno());
        List<FormalPos> formalPos1 = posService.selectFormalPosList(fp);
        if (CollectionUtils.isNotEmpty(formalPos1)) {
            return AjaxResult.error("当前机器已使用,不可重复绑定");
        }

        FormalPos fp1 = new FormalPos();
        fp1.setMerno(merNo);
        List<FormalPos> formalPos12 = posService.selectFormalPosList(fp1);
        if (CollectionUtils.isNotEmpty(formalPos12)) {
            return AjaxResult.error("商户已有绑定机器,请先解绑");
        }
        FormalPos formalPos = new FormalPos();
        formalPos.setPosno(bp.getPosno());
        formalPos.setMerno(merNo);
        formalPos.setAgentNum(bp.getAgentNum().toString());
        formalPos.setMachineNum(sn);
        formalPos.setPosType(bp.getPosType());
        formalPos.setStatus(Long.parseLong("0"));
        formalPos.setManuNum(bp.getManuNum());
        formalPos.setSimFee(bp.getSimFee());
        formalPos.setSimEnd(DateUtils.getDay("yyyyMMdd", Integer.parseInt(bp.getSim_end()),DateUtils.getDateYyyyMMdd()));
        formalPos.setService_fee(bp.getService_fee());
        formalPos.setService_end(DateUtils.getDay("yyyyMMdd", Integer.parseInt(bp.getService_end()),DateUtils.getDateYyyyMMdd()));
        posService.insertFormalPos(formalPos);

        MerchantInfo mi = new MerchantInfo();
        mi.setMerno(merNo);
        mi.setAgentNo(bp.getAgentNum().toString());
        merchantInfoService.updateMerchantInfo(mi);

        BranchPos bb = new BranchPos();
        bb.setIsbound(Long.parseLong("1"));
        bb.setId(bp.getId());
        branchPosService.updateBranchPos(bb);

        MerchantInfo merchantInfo = merchantInfoService.selectMerchantInfoById(merNo);

        JSONObject reqData = new JSONObject();
        reqData.put("orgMerNo",merchantInfo.getOrgMerno());
        reqData.put("machineNum",sn);
        Map<String, String> resp = PublicJgRequest.getReqData(reqData.toJSONString(), AutoLoadData.supplement);
        if (!"200".equals(resp.get("statusCode"))) {
            throw new BusinessException(resp.get("message"));
        }
        Map sendMap = new HashMap();
        sendMap.put("SHOW_LEGALCERNO",merchantInfo.getShowLegalcerno());
        sendMap.put("SHOW_LINKPHONE",merchantInfo.getShowLinkphone());
        sendMap.put("MERNO",merchantInfo.getMerno());
        sendMap.put("machineNum",sn);
        sendMap.put("AGENT_NO",bp.getAgentNum());
        sendMap.put("LEGAL_NAME",merchantInfo.getLegalName());
        agentAsyncService.executeAsyncTask(sendMap);
        return AjaxResult.success();
    }


    @PostMapping("/saveExpiry")
    @ResponseBody
    @Log(title = "手动处理有效", businessType = BusinessType.UPDATE)
    @Transactional
    public AjaxResult saveExpiry(@RequestParam Map param) throws Exception {
        String lergNo = String.valueOf(param.get("lergNo"));
        String merno = String.valueOf(param.get("merNo"));
        MerchantInfo mi = new MerchantInfo();
        mi.setLegalDate(lergNo);
        mi.setMerno(merno);
        merchantInfoService.updateMerchantInfo(mi);

        MerchantInfo merchantInfo = merchantInfoService.selectMerchantInfoById(merno);
        //请求变更
        JSONObject reqBody = new JSONObject();
        reqBody.put("orgMerNo",merchantInfo.getLdMerno());
        reqBody.put("orgSerial",merchantInfo.getOrgMerno());
        reqBody.put("relationNum",merchantInfo.getOrgSerial());
        reqBody.put("merNature","1");
        reqBody.put("lergNo","1");
        reqBody.put("legalDate",lergNo);
        Map<String, String> reqData = PublicJgRequest.getReqData(reqBody.toJSONString(), AutoLoadData.updateMerchant);
        if (!"200".equals(reqData.get("statusCode"))) {
            throw new BusinessException(reqData.get("message"));
        }
        return success();
    }


    @PostMapping("/savePushPos")
    @ResponseBody
    @Log(title = "手动推送绑定终端", businessType = BusinessType.UPDATE)
    @Transactional
    public AjaxResult savePushPos(@RequestParam Map param) throws Exception {
        String merNo = String.valueOf(param.get("merNo"));
        String sn = String.valueOf(param.get("sn"));
        BranchPos bp = branchPosService.selectBranchPosBySn(sn);
        if (bp == null) {
            return AjaxResult.error("sn不存在或未分配");
        }
        MerchantInfo merchantInfo = merchantInfoService.selectMerchantInfoById(merNo);
        Map sendMap = new HashMap();
        sendMap.put("SHOW_LEGALCERNO",merchantInfo.getShowLegalcerno());
        sendMap.put("SHOW_LINKPHONE",merchantInfo.getShowLinkphone());
        sendMap.put("MERNO",merchantInfo.getMerno());
        sendMap.put("machineNum",sn);
        sendMap.put("AGENT_NO",bp.getAgentNum());
        sendMap.put("LEGAL_NAME",merchantInfo.getLegalName());
        AjaxResult ajaxResult = agentAsyncService.executeAsyncTaskBulu(sendMap);
        return ajaxResult;
    }



    @GetMapping("/merReplacePos")
    public String merReplacePos(@RequestParam String merNo, ModelMap mmap) throws Exception {
        //商户信息
        Map merchantInfo = merchantInfoService.findMerchantInfoByMerNo(merNo);
        FormalPos formalPos = new FormalPos();
        formalPos.setMerno(merchantInfo.get("MERNO").toString());
        List<FormalPos> formalPos1 = posService.selectFormalPosList(formalPos);
        //终端SN编号
        String posNo = "";
        Long id = null;
        if (CollectionUtils.isNotEmpty(formalPos1)) {
            FormalPos formalPos2 = formalPos1.get(0);
            posNo = formalPos2.getMachineNum();
            id = formalPos2.getId();
        }
        mmap.put("merchantInfo", merchantInfo);
        mmap.put("posNo", posNo);
        mmap.put("id", id);
        return prefix + "/merReplacePos";
    }

    /**
     * 前往商户换机GB页面
     */
    @GetMapping("/merReplacePosGB")
    public String merReplacePosGB(@RequestParam String merNo, ModelMap mmap) throws Exception {
        //商户信息
        Map merchantInfo = merchantInfoService.findMerchantInfoByMerNo(merNo);
        FormalPos formalPos = new FormalPos();
        formalPos.setMerno(merchantInfo.get("MERNO").toString());
        List<FormalPos> formalPos1 = posService.selectFormalPosList(formalPos);
        //终端SN编号
        String posNo = "";
        Long id = null;
        if (CollectionUtils.isNotEmpty(formalPos1)) {
            FormalPos formalPos2 = formalPos1.get(0);
            posNo = formalPos2.getMachineNum();
            id = formalPos2.getId();
        }
        mmap.put("merchantInfo", merchantInfo);
        mmap.put("posNo", posNo);
        mmap.put("id", id);
        return prefix + "/merReplacePosGB";
    }


    /**
     * 商户迁移
     *
     * @Param [merno, agentNum]
     * @Return com.hjm.framework.web.domain.AjaxResult
     */
    @PostMapping("/merMigrateUpdate")
    @ResponseBody
    @Log(title = "迁移商户", businessType = BusinessType.UPDATE)
    public AjaxResult merMigrateUpdate(@RequestParam Map param) throws BusinessException {
        String merNo = String.valueOf(param.get("merNo"));
        String agentNum = String.valueOf(param.get("agentNum"));
        if (StringUtils.isEmpty(merNo)) {
            return error("商户编号不能为空");
        }
        if (StringUtils.isEmpty(agentNum)) {
            return error("代理编号不能为空");
        }
        return merchantInfoService.merMigrateUpdate(merNo, agentNum);
    }


    /**
     * 商户换机
     *
     * @Param [merNo, posNo,newPosNo]
     * @Return com.hjm.framework.web.domain.AjaxResult
     */
    @PostMapping("/merReplacePos")
    @ResponseBody
    @Log(title = "商户换机", businessType = BusinessType.UPDATE)
    public AjaxResult merReplacePos(@RequestParam Map<String, String> param) throws Exception {
        try {
            int i = merchantInfoService.merReplacePos(param);
            //开始进行接口库换机
            HashMap request = new HashMap<>();
            request.put("oldSn", param.get("posNo"));
            request.put("newSn", param.get("newPosNo"));
            request.put("merno", param.get("merNo"));
            merchantInfoService.manageJkPosKeyInfo(request);
            return success();
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    /**
     * 商户换机GB
     *
     * @Param [merNo, posNo,newPosNo]
     * @Return com.hjm.framework.web.domain.AjaxResult
     */
    @PostMapping("/merReplacePosGB")
    @ResponseBody
    @Log(title = "商户换机GB", businessType = BusinessType.UPDATE)
    public AjaxResult merReplacePosGB(@RequestParam Map<String, String> param) throws Exception {
        try {
            int i = merchantInfoService.merReplacePosGB(param);
            //开始进行接口库换机
            HashMap request = new HashMap<>();
            request.put("oldSn", param.get("posNo"));
            request.put("newSn", param.get("newPosNo"));
            request.put("merno", param.get("merNo"));
            merchantInfoService.manageJkPosKeyInfoGB(request);
            return success();
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    /**
     * 商户换机GB
     *
     * @Param [merNo, posNo,newPosNo]
     * @Return com.hjm.framework.web.domain.AjaxResult
     */
    @PostMapping("/merReplacePosGb")
    @ResponseBody
    @Log(title = "商户换机GB", businessType = BusinessType.UPDATE)
    public AjaxResult merReplacePosGb(@RequestParam Map<String, String> param) throws Exception {
        try {
            int i = merchantInfoService.merReplacePos(param);
            //开始进行接口库换机
            HashMap request = new HashMap<>();
            request.put("oldSn", param.get("posNo"));
            request.put("newSn", param.get("newPosNo"));
            request.put("merno", param.get("merNo"));
            merchantInfoService.manageJkPosKeyInfo(request);
            return success();
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }


    @GetMapping("/selectMerRate/{merno}")
    public String selectMerRate(@PathVariable("merno") String merno, ModelMap mmap) {
        mmap.put("merno", merno);
        return prefix + "/selectMerRate";
    }

    @PostMapping("/selectMerRate")
    @ResponseBody
    public TableDataInfo selectMerRate(String merno) {
        startPage();
        List<Map<String, Object>> list = merchantInfoService.getMerchantRate(merno);
        return getDataTable(list);
    }

    /**
     * 商户最新信息
     *
     * @Param [merno, sign]
     * @Return java.lang.String
     */
    @GetMapping("newMerchantInfo")
    public String newMerchantInfo(String merno, ModelMap mmap) throws Exception {
        //商户信息

        MerchantShow merchant = merchantInfoService.getMerchantInfoShow(merno);
        List<MerchantRateShow> merchantRateList = merchantInfoService.getMerchantRateShow(merno);
        mmap.put("merchant", merchant);
        mmap.put("merchantRateList", merchantRateList);
        return prefix + "/newMerchantInfo";
    }


    /**
     * 获取上游商户信息
     *
     * @Param [merno, sign]
     * @Return java.lang.String
     */
    @RequestMapping("getNewRateInfo")
    @ResponseBody
    public AjaxResult getNewRateInfo(@RequestParam Map<String, String> params) throws Exception {
        try {
            //商户信息
            return merchantInfoService.getMerNewchantRate(params.get("merno"), params.get("apply_id"));
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }


    /**
     * 重庆商户基本信息同步展业端管理
     *
     * @Param [merno, sign]
     * @Return java.lang.String
     */
    @RequestMapping("/syncMerInfo")
    @ResponseBody
    @Log(title = "重庆同步展业端管理", businessType = BusinessType.UPDATE)
    public AjaxResult syncMerInfo(@RequestBody JSONObject data) {
        return merchantInfoService.syncMerInfo(data);
    }

    /**
     * 商户同步
     *
     * @Param [merno, sign]
     * @Return java.lang.String
     */
    @PostMapping("/merSyn")
    @ResponseBody
    @Log(title = "商户同步", businessType = BusinessType.UPDATE)
    public AjaxResult merSyn(String merno) {
        //获取商户的848渠道商户号
        MerchantInfo merchantInfo = merchantInfoService.selectMerchantInfoById(merno);
        Integer merTb = merchantInfo.getMerTb();
        if (merTb!=2){
            return AjaxResult.error("只可同步重庆商户");
        }
        String ldMerno=merchantInfo.getLdMerno();
        JSONObject req = new JSONObject();
        req.put("merNo", ldMerno);
        //发送指定地址获取请求结果
        JSONObject data = null;
        try {
            String send = HttpUtils.send(AutoLoadData.sendLdMerNo, req, "UTF-8");
            JSONObject jsonObject = JSONObject.parseObject(send);
            data = jsonObject.getJSONObject("data");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        //调用syncMerInfo 方法
        return merchantInfoService.syncMerInfo(data);
    }

    /**
     * 前往新商户迁移页面
     */
    @GetMapping("/newMerMigrate")
    public String newMerMigrate(@RequestParam String merNo, ModelMap mmap) throws Exception {
        //商户信息
        Map merchantInfo = merchantInfoService.findMerchantInfoByMerNo(merNo);
        MerchantInfo merchantInfo1 = merchantInfoService.selectMerchantInfoById(merNo);
        String agentNum = "";
        String agentName = "";
        if (merchantInfo1 != null) {
            agentNum = merchantInfo1.getAgentNo();
        }
        if (StringUtils.isNotEmpty(agentNum)) {
            AgentInfo agentInfo = agentInfoService.selectAgentInfoByAgentNum1(agentNum);
            if (agentInfo != null) {
                agentName = agentInfo.getAgentName();
            }
        }
        FormalPos formalPos = posService.selectFormalPosByMerNo(merNo);
        String sn = "";
        String reachAgentNum = "";
        String actAgentNum = "";
        String flowAgentNum = "";
        if (formalPos != null) {
            sn = formalPos.getMachineNum();
            if (branchPosService.selectBranchPosBySn(sn) != null) {
                BranchPos branchPos = branchPosService.selectBranchPosBySn1(sn);

                if (StringUtils.isNotEmpty(branchPos.getReachAgentNum())) {
                    reachAgentNum = branchPos.getReachAgentNum();
                } else {
                    reachAgentNum = agentNum;
                }
                if (StringUtils.isNotEmpty(branchPos.getActAgentNum())) {
                    actAgentNum = branchPos.getActAgentNum();
                } else {
                    actAgentNum = agentNum;
                }
                if (StringUtils.isNotEmpty(branchPos.getFlowAgentNum())) {
                    flowAgentNum = branchPos.getFlowAgentNum();
                } else {
                    flowAgentNum = agentNum;
                }
            } else {
                if (StringUtils.isEmpty(actAgentNum)) {
                    actAgentNum = agentNum;
                }
                if (StringUtils.isEmpty(reachAgentNum)) {
                    reachAgentNum = agentNum;
                }
                if (StringUtils.isEmpty(flowAgentNum)) {
                    flowAgentNum = agentNum;
                }
            }
        }

        mmap.put("merchantInfo", merchantInfo);
        mmap.put("sn", sn);
        mmap.put("agentNum", agentNum);
        mmap.put("agentName", agentName);
        mmap.put("reachAgentNum", reachAgentNum);
        mmap.put("actAgentNum", actAgentNum);
        mmap.put("flowAgentNum", flowAgentNum);
        return prefix + "/newMerMigrate";
    }

    /**
     * 新商户迁移
     *
     * @Param [merno, agentNum]
     * @Return com.hjm.framework.web.domain.AjaxResult
     */
    @PostMapping("/newMerMigrateUpdate")
    @ResponseBody
    @Log(title = "新迁移商户", businessType = BusinessType.UPDATE)
    public AjaxResult newMerMigrateUpdate(@RequestParam Map param) throws BusinessException {
        String merNo = String.valueOf(param.get("merNo"));
        String agentNum = String.valueOf(param.get("newAgentNum"));
        String reachAgentNum = String.valueOf(param.get("reachAgentNum"));
        String actAgentNum = String.valueOf(param.get("actAgentNum"));
        String flowAgentNum = String.valueOf(param.get("flowAgentNum"));
        if (StringUtils.isEmpty(merNo)) {
            return error("商户编号不能为空");
        }
        if (StringUtils.isEmpty(agentNum)) {
            return error("代理编号不能为空");
        }
        //法人信息必须相同
        if (String.valueOf(param.get("legalName")).equals(String.valueOf(param.get("commissary"))) &&
                String.valueOf(param.get("merShowScreenidnum")).equals(String.valueOf(param.get("showScreenidnum")))) {
            return merchantInfoService.newMerMigrateUpdate(merNo, agentNum, reachAgentNum, actAgentNum, flowAgentNum);
        } else {
            return error("商户法人信息和服务商法人信息不一致");
        }
    }



    /**
     * 商户信息同步页面跳转
     */
    @GetMapping("/updateMerMes/{merNo}")
    public String updateMerMes(@PathVariable("merNo") String merNo, ModelMap mmap) throws Exception {
        //商户信息
        MerchantInfo merchantInfo = merchantInfoService.selectMerchantInfoById(merNo);
        mmap.put("merchantInfo", merchantInfo);
        //商户账户信息
        Accounts account = new Accounts();
        account.setSeqId(merchantInfo.getMerno());
        Accounts accounts = accountsService.selectAccounts(account);
        //根据地区名称获取代号
        String addressName = accounts != null ? accounts.getAreaName() : "";
        String province = "";
        String city = "";
        String areaName = "";
        if (StringUtils.isNotEmpty(addressName)) {
            String[] addressArray = addressName.split(",");
            if (addressArray.length > 1) {
                if (StringUtils.isNotEmpty(addressArray[0])) {
                    province = addressArray[0];
                    Map<String, Object> params = new HashMap();
                    params.put("area_name", province);
                    params.put("area_type", "0");
                    Map<String, Object> areaCodeMap = areaService.findQBAreaCode(params);
                    province = String.valueOf(areaCodeMap != null ? areaCodeMap.get("AREA_CODE") : "");
                    mmap.put("province", String.valueOf(areaCodeMap != null ? areaCodeMap.get("AREA_CODE") : ""));
                }
                if (StringUtils.isNotEmpty(addressArray[1])) {
                    city = addressArray[1];
                    Map<String, Object> params = new HashMap();
                    params.put("area_name", city);
                    params.put("area_type", "1");
                    Map<String, Object> areaCodeMap = areaService.findQBAreaCode(params);
                    city = String.valueOf(areaCodeMap != null ? areaCodeMap.get("AREA_CODE") : "");
                    mmap.put("city", String.valueOf(areaCodeMap != null ? areaCodeMap.get("AREA_CODE") : ""));
                }
            }
            if (addressArray.length > 2) {
                if (StringUtils.isNotEmpty(addressArray[2])) {
                    areaName = addressArray[2];
                    Map<String, Object> params = new HashMap();
                    params.put("area_name", areaName);
                    params.put("area_type", "2");
                    Map<String, Object> areaCodeMap = areaService.findQBAreaCode(params);
                    mmap.put("area", String.valueOf(areaCodeMap != null ? areaCodeMap.get("AREA_CODE") : ""));
                }
            }
        }
        List<Area> pList = new ArrayList<>();
        List<Area> cList = new ArrayList<>();
        List<Area> aList = new ArrayList<>();
        List<Area> areas = areaService.selectAreaList(null);
        for (Area area : areas) {
            if (area.getAreaType() == 0) {
                pList.add(area);
            } else if (area.getAreaType() == 1 && province.equals(area.getParentId())) {
                cList.add(area);
            } else if (area.getAreaType() == 2 && city.equals(area.getParentId())) {
                aList.add(area);
            }
        }
        mmap.put("pList", pList);
        mmap.put("cList", cList);
        mmap.put("aList", aList);

        if(accounts == null){
            accounts = new Accounts();
        }
        accounts.setScreenNum(accounts.getScreenNum() != null ? EncryptUtils.getDecrypt(accounts.getScreenNum()) : "");
        accounts.setScreenIdnum(accounts.getScreenIdnum() != null ? EncryptUtils.getDecrypt(accounts.getScreenIdnum()) : "");
        accounts.setResphone(accounts.getResphone() != null ? EncryptUtils.getDecrypt(accounts.getResphone()) : "");

        mmap.put("accounts", accounts);


        return prefix + "/updateMerMes";
    }


    /**
     * 商户修改结算银行
     */
    @PostMapping("/updateMerMes")
    @Log(title = "商户信息同步", businessType = BusinessType.UPDATE)
    @ResponseBody
    public AjaxResult updateMerMes(@RequestParam Map<String, String> params,String merno, HttpServletRequest request) throws Exception{
        return merchantInfoService.updateMerMes(params, merno, request, ShiroUtils.getSysUser().getObjNo());
    }

    /**
     * 商户注册地址变更记录
     * @return
     */
    @RequestMapping("/merUpdateAreaRecord")
    public String merUpdateAreaRecord(){
        return "merchantInfo/merRecord/merUpdateAreaRecord";
    }

    /**
     * 查询商户注册地址变更记录
     * @return
     */
    @RequestMapping("/merUpdateAreaRecordList")
    @ResponseBody
    public TableDataInfo merUpdateAreaRecordList(MerUpdateAreaRecord merUpdateAreaRecord){
        List<MerUpdateAreaRecord> list = new ArrayList<>();
        try {
            startPage();
            list = merchantInfoService.selectMerUpdateAreaRecordList(merUpdateAreaRecord);
        }catch (Exception e){
            e.printStackTrace();
        }
        return getDataTable(list);
    }

    @RequestMapping("/problem")
    public String problem() {
        return "merchantInfo/merchantInfo/problem";
    }

    @RequestMapping("/problemList")
    @ResponseBody
    public TableDataInfo problemList(@RequestParam Map param) {
        List<Map<String,Object>> list = new ArrayList<>();
        try {
            startPage();
            list = merchantInfoService.allProblemList(param);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return getDataTable(list);
    }

    /**
     * 查看图片
     * @return
     */
    @GetMapping("/lookImgProblem/{merNo}")
    public String lookImgProblem(@PathVariable("merNo") String merNo, ModelMap mmap) {
        ClientImg clientImg = new ClientImg();
        clientImg.setClientno(merNo);
        clientImg.setObjType(0L);
        List<ClientImg> clientImgs = clientImgService.selectclientImgList(clientImg);
        mmap.put("merNo", merNo);
        mmap.put("clientImgs", clientImgs);
        mmap.put("imgUrl", CustomConfig.getImgUrl());
        return prefix + "/lookImg";
    }

    /**
     * 打回
     * @param merno
     * @param type
     * @param mmap
     * @return
     */
    @RequestMapping("/repulseMerInfo/{merno}/{type}")
    public String repulseMerInfo(@PathVariable("merno") String merno,@PathVariable("type") String type, ModelMap mmap){
        //商户信息
        try {
            Map merchantInfo = merchantInfoService.findMerchantInfoByMerNo(merno);
            mmap.put("merchant", merchantInfo);
            mmap.put("merno", merno);
            mmap.put("type", type);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "merchantInfo/merchantInfo/repulseMerInfo";
    }

    /**
     * 通过/打回
     * @param merno
     * @param status
     * @param type
     * @param mer_status
     * @return
     */
    @RequestMapping("/updateProblemStatus/{merno}/{status}/{type}/{mer_status}")
    public @ResponseBody
    AjaxResult updateProblemStatus(@PathVariable("merno")String merno,@PathVariable("status") String status, @PathVariable("type") String type, @PathVariable("mer_status") String mer_status) {
        try {
            Map<String, Object> resultMap = merchantInfoService.updateProblemStatus(merno, Integer.parseInt(status), Integer.parseInt(type), Integer.parseInt(mer_status));
            if (Integer.parseInt(resultMap.get("result").toString()) > 0) {
                if (status.equals("1")) {
                    return AjaxResult.success("通过成功");
                } else {
                    return AjaxResult.success("打回成功");
                }
            } else {
                return AjaxResult.error(resultMap.get("msg").toString());
            }
        } catch (Exception e) {
           e.printStackTrace();
        }
        return AjaxResult.error("操作失败");
    }

    @RequestMapping("/merProblem")
    @ResponseBody
    public AjaxResult merProblem(String merno){
        try {
            //修改商户状态为人工审核
            int i = merchantInfoService.updateMerForProblem(merno);
            if(i > 0){
                return AjaxResult.success("操作成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return AjaxResult.error("操作失败");
    }

    /**
     * 变更商户状态
     * @param merno
     * @return
     */
    @RequestMapping("/updateMerSta")
    @ResponseBody
    public AjaxResult updateMerSta(String merno){
        try {
            //修改商户状态为正式商户
            AjaxResult i = merchantInfoService.updateMerStr(merno);
            return i;
        }catch (Exception e){
            e.printStackTrace();
        }
        return AjaxResult.error("操作失败");
    }

    /**
     * 接收钱创付推送数据
     *
     * @Param [merno, sign]
     * @Return java.lang.String
     */
    @RequestMapping("/syncQcfMerInfo")
    @ResponseBody
    @Log(title = "钱创付同步展业端管理", businessType = BusinessType.UPDATE)
    public AjaxResult syncQcfMerInfo(@RequestBody JSONObject data) {
        return merchantInfoService.syncQcfMerInfo(data);
    }

    /**
     * 设置结算
     */
    @GetMapping("/editMerRate")
    public String editMerRate(String merno,ModelMap map) {
        MerchantRate rate = new MerchantRate();
        rate.setMerno(merno);
        List<MerchantRate> merchantRates = merchantRateService.selectMerchantRateList(rate);
        MerchantCommon merchantCommon = MerchantRateUtils.dbToView(merchantRates);
        merchantCommon.setMerno(merno);
        map.put("merRate",merchantCommon);
        return prefix + "/editMerRate";
    }


    /**
     * 商户修改费率
     *
     * @Param [merno, sign]
     * @Return java.lang.String
     */
    @RequestMapping("/saveMerRate")
    @ResponseBody
    @Log(title = "商户修改费率", businessType = BusinessType.UPDATE)
    public AjaxResult saveMerRate(MerchantCommon merchantCommon) {
        AjaxResult ajaxResult = merchantRateService.updateMerchantRate(merchantCommon);
        return ajaxResult;
    }

}
